//
//  LZSpamCodeManager.m
//  LZSpamCode
//
//  Created by ZengLiZhi on 2024/6/21.
//

#import "LZSpamCodeManager.h"
#import "LZFilesCreator.h"
#import "LZStringRandom.h"
#import "LZChangeAsset.h"
#import "LZFileManager.h"
#import "LZChangeProject.h"
#import "LZChangeClassName.h"
#import "LZChangeComments.h"
#import "LZChangeFunctionName.h"
#include <stdlib.h>

@interface LZSpamCodeManager ()

@end

@implementation LZSpamCodeManager

+ (LZSpamCodeManager *)shareInstance{
    static LZSpamCodeManager *helper;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        if (helper == nil) {
            helper = [[LZSpamCodeManager alloc]init];
        }
    });
    return helper;
}

#pragma mark - 开始处理
- (void)start{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    NSError *error = nil;
    NSArray<NSString *> *files = [fileManager contentsOfDirectoryAtPath:self.gProjectPath error:&error];
    if (error) {
        NSLog(@"error:%@",error);
    }
    for (NSString *fileName in files) {
        if ([fileName containsString:@".xcodeproj"]) {
            self.gOldProjectName = [fileName stringByReplacingOccurrencesOfString:@".xcodeproj" withString:@""];
            NSLog(@"projectName:%@",self.gOldProjectName);
        }
    }
    
    BOOL isDirectory = NO;
    self.gSourceCodeDir = [NSString stringWithFormat:@"%@/%@",self.gProjectPath,self.gOldProjectName];
    if (![fileManager fileExistsAtPath:self.gSourceCodeDir isDirectory:&isDirectory]) {
        printf("%s不存在\n", [self.gSourceCodeDir UTF8String]);
        return;
    }
    if (!isDirectory) {
        printf("%s不是目录\n", [self.gSourceCodeDir UTF8String]);
        return;
    }
    
    //修改项目名
    [LZChangeProject start];
    
    //修改图片名和md5值
    [LZChangeAsset start];
    
    //删除注释
    [LZChangeComments start];
    
    //修改类名
    [LZChangeClassName start];
    
    //生成新文件（垃圾文件）
//    [LZFilesCreator start];
    
    //修改方法名
    [LZChangeFunctionName start];
}

@end
